import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'course_page.dart';
import 'home_page.dart';
import 'study_page.dart';
import 'user_page.dart';

class IndexPage extends StatefulWidget {
  IndexPage({Key key, String title}) : super(key: key);

  @override
  _IndexPageState createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage> {
  int _selectedIndex = 0;
  final List<BottomNavigationBarItem> bottomNavItems = [
    BottomNavigationBarItem(
      icon: Image.asset("assets/icons/maintab_home.png",width:20.0),
      activeIcon: Image.asset("assets/icons/maintab_home_h.png",width:20.0),
      title: Text('首页')),
    BottomNavigationBarItem(
      icon: Image.asset("assets/icons/maintab_course.png",width:20.0),
      activeIcon: Image.asset("assets/icons/maintab_course_h.png",width:20.0),
      title: Text('选课')),
    BottomNavigationBarItem(
      icon: Image.asset("assets/icons/maintab_study.png",width:20.0),
      activeIcon: Image.asset("assets/icons/maintab_study_h.png",width:20.0),
      title: Text('学习')),
    BottomNavigationBarItem(
      icon: Image.asset("assets/icons/maintab_my.png",width:20.0),
      activeIcon: Image.asset("assets/icons/maintab_my_h.png",width:20.0),
      title: Text('我的')),
  ];
  final pages = [HomePage(),CoursePage(),StudyPage(),UserPage()];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar( // 底部导航
        items: bottomNavItems,
        currentIndex: _selectedIndex,
        type: BottomNavigationBarType.fixed,
        fixedColor: Color(0xFF3A3C42),
        onTap: _onItemTapped,
      ),
      body: pages[_selectedIndex],
    );
  }

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }
}